package main

import (
	"os"
	"fmt"
	"go-glue.googlecode.com/hg/rlglue"
)

func main() {
	var err os.Error
	defer func() {
		if err != nil {
			panic(err)
		}
	}()
	gt := &GlueTester{"test_rl_episode", 0, 0}
	ex := new(rlglue.Experiment)
	if err = ex.AutoConnect(); err != nil {
		return
	}
	if _, err = ex.Init(); err != nil {
		return
	}
	var isTerminal, steps int32
	isTerminal, err = ex.Episode(0)
	gt.check(isTerminal != 1)
	steps, err = ex.NumSteps()
	gt.check(steps != 5)
	isTerminal, err = ex.Episode(1)
	gt.check(isTerminal != 0)
	steps, err = ex.NumSteps()
	gt.check(steps != 1)
	isTerminal, err = ex.Episode(2)
	gt.check(isTerminal != 0)
	steps, err = ex.NumSteps()
	gt.check(steps != 2)
	isTerminal, err = ex.Episode(4)
	gt.check(isTerminal != 0)
	steps, err = ex.NumSteps()
	gt.check(steps != 4)
	isTerminal, err = ex.Episode(5)
	gt.check(isTerminal != 0)
	steps, err = ex.NumSteps()
	gt.check(steps != 5)
	isTerminal, err = ex.Episode(6)
	gt.check(isTerminal != 1)
	steps, err = ex.NumSteps()
	gt.check(steps != 5)
	isTerminal, err = ex.Episode(7)
	gt.check(isTerminal != 1)
	steps, err = ex.NumSteps()
	gt.check(steps != 5)
	if err = ex.Cleanup(); err != nil {
		return
	}
	if err = ex.Close(); err != nil {
		return
	}
	fmt.Printf("%v\n", gt)
	os.Exit(gt.failCount)
}
